// 文章相关的所有的请求
import http from '@/utils/request.js'

export const reqGetArticles = (queryObj) => {
  // get 请求的参数，在params中传递，会在地址栏拼接
  return http({
    method: 'get',
    url: '/mp/v1_0/articles',
    params: queryObj || {}
  })
}

/**
 * 获取文章频道
 */
export const reqGetChannels = () => {
  return http({
    method: 'get',
    url: '/mp/v1_0/channels'
  })
}

/**
 * 删除频道数据
 */
export const reqDeleteArticle = (articleId) => {
  return http({
    method: 'delete',
    url: `/mp/v1_0/articles/${articleId}`
  })
}

/**
 * 添加文章
 * idDraft 是否草稿
 */
export const reqAddArticle = (isDraft, article) => {
  return http({
    method: 'post',
    url: '/mp/v1_0/articles',
    params: {
      draft: isDraft
    },
    data: article
  })
}

/**
 * 根据id获取文章详情
 * id:修改的文章的id
 * draft:是否草稿，布尔值
 * data:文章信息对象
 * @param {*} id
 */
export const reqGetArticleById = (id) => {
  return http({
    method: 'get',
    url: `/mp/v1_0/articles/${id}`
  })
}

/**
 * 根据id保存修改文章详情
 */
export const reqEditArticle = (id, draft, data) => {
  return http({
    method: 'put',
    url: `/mp/v1_0/articles/${id}`,
    params: {
      draft
    },
    data
  })
}
